package com.jxdinfo.hussar.activitidemo.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
    public String dateToString(Date date){
        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        String now = dateFormat.format(date);
        return now;
    }
    /**
     * 获取当前系统时间
     * @param fomt
     * @return
     */
    public static String getNowDate(String fomt){
    	 SimpleDateFormat dateFormat=new SimpleDateFormat(fomt);
    	 return dateFormat.format(new Date());
    }
    /**
     * 日期差
     * @param d1
     * @param d2
     * @return
     */
    public static int getDateSub(String d1,String d2) throws Exception{
    	SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
    	Date sdate = dateFormat.parse(d1);
    	Date edate = dateFormat.parse(d2);
		int result = -1;
		long start = sdate.getTime();
		long end = edate.getTime();
		result = (int)(end-start)/(1000*24*60*60);
		return result;
	}
    /**
     * 根据差求日期
     * @throws Exception 
     */
    public static String getDateToString(String datestr,int c){
    	SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
    	try {
    		Date date = dateFormat.parse(datestr);
        	long start = date.getTime();
        	long end = start+(c+1)*1000*24*60*60;
        	date.setTime(end);
        	String endDate = dateFormat.format(date);
        	return endDate;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return "";
		}
    	
    }

    
    public static void main(String[] args) throws Exception{
    	System.out.println(getDateSub("2019-01-28", "2019-02-01"));
    }

}
